﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using qltscd.Models;
using qltscd.Models.ScreenClient;
using qltscd.Contansts;
using Telerik.Web.Mvc;
using qltscd.Helper;
namespace qltscd.Controllers
{
    public class NhaCungCapController : BaseController {
        #region Properties Section
        private QLTBEntities db = new QLTBEntities();
        #endregion

        #region Views Section
        public ViewResult Index()
        {
            NCCScreenClient screen = new NCCScreenClient();
            if (Session[SessionScreenContansts.NHA_CUNG_CAP_SCREENCLIENT] != null) {
                screen = (NCCScreenClient)Session[SessionScreenContansts.NHA_CUNG_CAP_SCREENCLIENT];
            }
            Search(screen);
            return View(screen);
        }
        [HttpPost]
        public ActionResult Index (NCCScreenClient screen) {
            Search(screen);
            return View(screen);
        }

        [GridAction]
        public ActionResult _Index () {
            NCCScreenClient screen = new NCCScreenClient();
            if (Session[SessionScreenContansts.NHA_CUNG_CAP_SCREENCLIENT] != null) {
                screen = (NCCScreenClient)Session[SessionScreenContansts.NHA_CUNG_CAP_SCREENCLIENT];
            }
            Search(screen);
            return View(new GridModel(screen.DSNhaCungCap));
        }
        #endregion

        #region CRUD Section

        #endregion

        #region Helper Section
        private void Search (NCCScreenClient screen) {
            if (Session[SessionScreenContansts.NHA_CUNG_CAP_SCREENCLIENT] != null) {
                screen = (NCCScreenClient)Session[SessionScreenContansts.NHA_CUNG_CAP_SCREENCLIENT];
            } else {
                screen = new NCCScreenClient();
            }
            screen.DSNhaCungCap.Clear();
            var list = db.DanhMucNhaCungCaps.OrderBy(i => i.TenNhaCungCap).ToList();
            foreach (DanhMucNhaCungCap ncc in list) {
                qltscd.Models.BaseClient.DanhMucNhaCungCap nccClient = new Models.BaseClient.DanhMucNhaCungCap();
                ObjectHelper.Copy(ncc, nccClient);
                screen.DSNhaCungCap.Add(nccClient);
            }
            Session[SessionScreenContansts.NHA_CUNG_CAP_SCREENCLIENT] = screen;
        }
        #endregion

        #region Additional Section
        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
        #endregion

        #region Sub Section

        #endregion
    }
}